Fixed Bugs (NullPointerExceptions)

Fixed bugs that were leading to runtime errors