Reorganized a bit. Refer to last commit for code changes.