Attempt at optimizing