More tests and cleaner code