general refactor: fixes #2 #4 and #5