Reorganization/cleanup of code