cleaned up some duplicated code