More documentation and refractoring