added another check and removed unnecessary code, and added a test project