Implemented #28 and minor fixes