First version of code. Not all functionallity is working