Added  $ removal. Improved logic.