unitized the code a bit more