fixed error and logic