Added code to handle mem buttons - there are still some issues in handling them.