Some security checks added and bugs cleared.