bug fixes and a little error fix