cleaned up duplicated code