Oh dear God, please someone save me from this ugly code...