Removed unnedded code.
Added tests.

* Tests from @epidemian, thanks!