Split into modules and better tests