Refector code a bit