Moved working tully code into main program