Removed deprecated MySQL API (replaced with PDO), security improvements, minor fixes, minor refactoring