refactored naming and added guard statements