more styling changes, and logic to prevent undefined results