simplified the code a bit