working except for spare message
fully working after refactoring