moved opt handling to functions