Fixing some bugs that were hidden by uninitialied memory