Cleaned up code. Still need to finalize