fixed docs, optimized code