Improved documentation
Made API more robust