removed duplicate code and moved things around