fixes and refactoring, v0.3.1