Added a lot more handling in case crazyness happens.