Refactored functions into appropriate lib files

Change-Id: Idb1568e0a925df20369fe7624c2c440057c4edc2