Code consolidation + general tweaks