Cleanup and reduce code