Bug fixed, tests added

Simple fix, new tests added to cover it