Cleaned up code according to Code Analysis