Tests and major refactor

[#16]