refactored with self and msg, key variables