Minor code cleanup, added comments etc.