added docs, fixed a bug