fixed a major bug and added security where it lacked