More code improvents and documentation