added tests, fixed code via willems comments