splits up method, removes some duplication