Refactoring (removed some unnesseccary casts and added some null controls)