moved code to methods