isolate optimisation to the library

Signed-off-by: Mattias Andrée <maandree@operamail.com>