refactor spacing code (also fixes weird spacing