Refector the code a bit