Fixed logging. Checked for failed writes and re-opens the log file if log path exists.
Added mangle and unmangle string functions (de/encrypts using mcrypt).