FINAL cleaned up code