numerous additions and bug fixes