main part, maybe some errors here