Refactored a bit

adds test

Have fun with this one :D