Add missing documentation and tune code a bit