reorganiziging the code structure. Still not working (WIP)