probably could have used a library for this : )