Move code to static library and example