these actions being embedded in this function has always been sub-optimal.If you have any ideas feel free to improve