added a lot of documenting comments
fixed some errors