code refactored for console message
code refactored when the page loading is finished