Finished most of the functionality