fixed some mistakes and finalized most of it. May be some more changes to
make when in server mode