bug fixes and more functions