Add more safety checks
Improve documentation