fixed some window msg's and added security checks.