Fix NullPointerException and ClassCastException in SyncHandler