Cleaned up code a bit. Still some cleaning could be applied.