commented, refacterd & formatted