Fixed bugs and finished functions