Refactor code, more tests and improve README