Move logging functions into lib
Use a different copying strategy when applying