working, modified code structure