refactored the repetitive parts of the functions for better mapping