refactor and new functions and procedures
merge