Code commented and made pretty