Cleanup and modularize