Cleaned up the createAction function and added a bunch of comments to improve readability