moving/splitting some code pieces