Some comments added for readability