Implemented some checks to make it a bit more secure