Added additional testing, logging, and corrected potential security problem