Graphics algorithms bugfixing