Added input verification + made some functions private