comments added, code cleaned up