implemented message passing by returning map of functions instead of using a conditional