refactor to separate lib file, and added dynamicimage boolean