Fixed functions

Fixed some functions and made documentation.