Fixed copy table logic and some refactorings