Code improvements for less lag