Extracted implimentation to lib