Fixed some of the problems mentioned in issue #27