Cleaner code & some tests