Refractor code for less copypasta later