fixed doubling bug; added a bunch of validation