all functioning AOK. requires more comments and refactoring