Refactoring of some common functions and typos