Cleanup code and DRY