Done core function
Several bug fixes