Major refactoring and cleanup

This is a very breaking change!