code refactored
some more fixes