More cleanup and make code more secure