refined some code