included bugfixes from sajnikanth.com