Code optimization

arrays instead of lists where possible