made some changes to improve code