functionalize some code