Reworked the code a little