Added functionality and correct bugs