edited the code for readability