minor optimization and added docs