Added custom logging and a little clean up