Nearly completed

Still needs testing and possibly some error handling