Improved readability and added a logging