Complete TP2. Still need some cleaning and error handling.