Put everything into function