done issue #61; some code refactored