Refactor calculate and parse functions