Fix returns and document some functions