fixed few bugs and add small functions