general refactor: fixes #2 #4 and #5

general refactor