Enhancement 4 implementation. Enhancement 2 slightly optimised