Added some input and security checks

A couple of screwy line ending changes but they shouldn't effect anything.