Small changes for stability and cleanup code