Put library code up top
Fix some stuffs