Updated somewhat to compile without warnings