fixing bugs and add functionality