functionalize the code