Simplified code and added docscript