Fixed bugs and added functions