Porting some of the bug fixes from 0.2 to 0.1