fixed runtime errors
removing some compiler warnings