cleanup
move some functions