modified directions feature to use regex to extract parameters and modularized the function