refactored some non-dry (wet?) code