fixed minor function bugs.