Without testing your code...
One thing jumps out at me. When $ is used in quotes, it should be $$.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.