more elegant code structure