moved functions and made them prototype