added documentation and increased readability