Created handleCustomAction function to clean code