bug fixes and add functions