cleanup and modularize more