Added P039, P047, and P049

Also more edits to Library and other files for style/runtime