some more refactoring
fixed test
add tested with ghc 7.6.2