Amended code
Amended readability and performance