bug fixes and some added functions