Added #50, removed unused functions, fix debugs