Refined some errors in the code