extracted out methods and added more documentation