Various code fixes and moving some files around