Rewrote messy put function