Some minor code refactor