slight polishing and implementing some security features