moved code from global scope to main method