restructured some code