Refactoring code to remove more bugs before release of 0.2.0