Cleaning up duplicated code