Fix some null reference exceptions in some cases and wrong mapping