bug fixes and new functions