included bug fixes from sajnikanth.com