Fixed divide by zero bug; added guards