Code clean up and settings implementation