fixed #3 & refactor