updated usage
changed order of filename and template
moved some functionality into libs