refactored for greater maintainabiliy and cohesiveness