Clean up duplicated code