added spent by and cleaned up code