fixed many things and made code cleaner with setup function