Code cleanup and re-org