some changes - main almost works