Some cleanup and bug resolving