Updated, added more error checking.