added documentation, fixed more bugs