moving some code to helper classees and code cleanup