Added documentation and moved types to top