finished all functions. Only main remaining