refactored partial code