Worked on dispatcher function. Added some error checks.