code refactoring to reduce duplicate code and unneeded use of options hashes