Big edit of code, first of major changes.