fixed Bugs and added functions