re-format the code & add test functions