Moved sync part to separate file