fix #1, fix #2, fix #3, fix #4, major refactoring