Fixed some duplicated code