add API docs, make code reflect documentation