Edited for readability and completeness