added code to function to make it output correctly and a ternary that needs to be fixed